//
//  RenameView.m
//  Router
//
//  Created by teki on 15/11/10.
//  Copyright © 2015年 dc. All rights reserved.
//

#import "RenameView.h"

@interface RenameView()

@property (nonatomic, strong) UIButton *backView;

@property (weak, nonatomic) IBOutlet UIView *contentView;

@property (weak, nonatomic) IBOutlet UIButton *closeButton;
@property (weak, nonatomic) IBOutlet UITextField *textField;
@property (weak, nonatomic) IBOutlet UIButton *assureButton;

@property (nonatomic, copy) AssureBlock block;
@end



@implementation RenameView

- (void)awakeFromNib
{
    self.assureButton.layer.cornerRadius = 20.0f;
    self.assureButton.layer.masksToBounds = YES;
    
    
}

+ (RenameView *)loadViewFromNib
{
    NSArray *array = [[NSBundle mainBundle] loadNibNamed:@"RenameView" owner:self options:nil];
    return [array firstObject];
}


- (IBAction)closeButtonPressed:(id)sender {
    [UIView animateWithDuration:0.3 animations:^{
        self.alpha = 0;
    } completion:^(BOOL finished) {
        [self removeFromSuperview];
    }];
}

- (IBAction)backViewPressed:(id)sender {
    [self closeButtonPressed:nil];
}

- (IBAction)assureButtonPressed:(id)sender {
    [self closeButtonPressed:nil];
    NSString *name = _textField.text;
    if (self.block)
    {
        self.block(name);
    }

}


#pragma mark -
#pragma mark   setters and getters 

- (void)setDeviceName:(NSString *)deviceName
{
    _deviceName = deviceName;
    _textField.text = deviceName;
}


- (void)setAssureBlcok:(AssureBlock)block
{
    _block = block;
}
@end
